SHELL = /bin/bash

repo="xiaobaiskill"
app="cdce-gateway"

run:
	npm start

docker-build:
	@echo "build docker image"
	@BRANCH_NAME=$(shell git rev-parse --abbrev-ref HEAD); \
	if [[ $$BRANCH_NAME == "develop" ]]; then \
		ENV="stage"; \
	elif [[ $$BRANCH_NAME == "master" ]]; then \
		ENV="prod"; \
	else \
		ENV="feat"; \
	fi; \
	docker build --build-arg GITHUB_USER=$$GITHUB_USER --build-arg GITHUB_TOKEN=$$GITHUB_TOKEN -t ${repo}/${app}:$$ENV .

docker-push:
	@echo "tag & docker push"
	@BRANCH_NAME=$(shell git rev-parse --abbrev-ref HEAD); SHA1_SHORT=$(shell git rev-parse --short HEAD); \
	if [[ $$BRANCH_NAME == "develop" ]]; then \
		ENV="stage"; \
	elif [[ $$BRANCH_NAME == "master" ]]; then \
		ENV="prod"; \
	else \
		ENV="feat"; \
	fi;  \
	docker tag  ${repo}/${app}:$$ENV   ${repo}/${app}:$$SHA1_SHORT; \
	docker push  ${repo}/${app}:$$SHA1_SHORT; \
	docker push  ${repo}/${app}:$$ENV;


